package dto

import "golang.org/x/oauth2"

type Oauth2 struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	Endpoint     Endpoint `json:"endpoint"`
	RedirectURL  string   `json:"redirect_url"`
	Scopes       []string `json:"scopes"`
	Code         string   `json:"code"`
}

func (o Oauth2) ToOauth2() oauth2.Config {
	return oauth2.Config{
		ClientID:     o.ClientID,
		ClientSecret: o.ClientSecret,
		Endpoint:     o.Endpoint.ToEndpoint(),
		RedirectURL:  o.RedirectURL,
		Scopes:       o.Scopes,
	}
}

type Endpoint struct {
	AuthURL       string `json:"auth_url"`
	DeviceAuthURL string `json:"device_auth_url"`
	TokenURL      string `json:"token_url"`
	AuthStyle     int    `json:"auth_style"`
}

func (e Endpoint) ToEndpoint() oauth2.Endpoint {
	return oauth2.Endpoint{
		AuthURL:       e.AuthURL,
		DeviceAuthURL: e.DeviceAuthURL,
		TokenURL:      e.TokenURL,
		AuthStyle:     oauth2.AuthStyle(e.AuthStyle),
	}
}
